package com.xsj.controller;

import com.xsj.dto.ResponseDto;
import com.xsj.pojo.Merchant;
import com.xsj.service.MerchantService;
import java.util.List;

import com.xsj.xzxDto.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "MerchantController")
@CrossOrigin
@RestController
@RequestMapping({"/merchant"})
public class MerchantController {
    @Autowired
    private MerchantService merchantService;

    @Operation(summary = "店铺信息", description = "根据当前用户经纬度获取附近店铺信息")
    @GetMapping({"/getMerInfoByLocation"})
    public ResponseDTO getMerInfoByLocation(@RequestParam("selectedAddress") String selectedAddress,
                                            @RequestParam("latitude") double latitude,
                                            @RequestParam("longitude") double longitude) {
        System.out.println(selectedAddress+"latitude:"+latitude+"longitude:"+longitude);
        return merchantService.getMerInfoByLocation(latitude,longitude,selectedAddress);
    }

    @Operation(summary = "店铺信息", description = "根据店铺类型获取所有店铺信息")
    @GetMapping({"/getMerchantInfo"})
    public ResponseDto getMerchantInfo(@RequestParam("typeId") Integer typeId,
                                       @RequestParam("selectedAddress") String selectedAddress,
                                       @RequestParam("latitude") double latitude,
                                       @RequestParam("longitude") double longitude) {
        return merchantService.getMerchantInfo(typeId, selectedAddress, latitude, longitude);
    }

    @Operation(summary = "店铺信息", description = "根据id获取店铺信息")
    @GetMapping({"/getMerchantInfoById"})
    public ResponseDto getMerchantInfoById(@RequestParam("merchantId") Integer merchantId) {
        Merchant merchantInfo = this.merchantService.getMerchantInfoById(merchantId);
        return ResponseDto.success(merchantInfo);
    }
    @Operation(summary = "店铺类型", description = "获取店铺类型")
    @GetMapping("/getMerchantType")
    public ResponseDto getMerchantType() {
        return ResponseDto.success(this.merchantService.getMerchantType());
    }
    @Operation(summary = "店铺信息", description = "根据id获取店铺信息")
    @GetMapping("/searchMerchant")
    public ResponseDto getMerchantTypeById(@RequestParam("search")String search) {
        return ResponseDto.success(this.merchantService.searchMerchant(search));
    }

}
